package testGroovy;

import groovy.json.JsonBuilder;

import javax.management.InstanceOfQueryExp;

def coverageInfo = [
	[
		"coverageCode": "DamageLossCoverage",
		"coverageName": "车辆损失险",
		"coverageAmount": "388000.0"
	],
	[
		"coverageCode": "DamageLossExemptDeductibleSpecialClause",
		"coverageName": "车损险不计免赔",
		"coverageAmount": ""
	],
	[
		"coverageCode": "ThirdPartyLiabilityCoverage",
		"coverageName": "第三者责任险",
		"coverageAmount": "1000000"
	],
	[
		"coverageCode": "ThirdPartyLiabilityExemptDeductibleSpecialClause",
		"coverageName": "三责险不计免赔",
		"coverageAmount": ""
	],
	[
		"coverageCode": "InCarPassengerLiabilityCoverage",
		"coverageName": "车上乘客责任险",
		"coverageAmount": "10000"
	],
	[
		"coverageCode": "InCarDriverLiabilityCoverage",
		"coverageName": "车上司机责任险",
		"coverageAmount": "10000"
	],
	[
		"coverageCode": "InCarPersonLiabilityExemptDeductibleSpecialClause",
		"coverageName": "车上人员责任险不计免赔",
		"coverageAmount": ""
	],
	[
		"coverageCode": "TheftCoverage",
		"coverageName": "全车盗抢损失险",
		"coverageAmount": "353080"
	],
	[
		"coverageCode": "TheftCoverageExemptDeductibleSpecialClause",
		"coverageName": "全车盗抢险不计免赔",
		"coverageAmount": ""
	],
	[
		"coverageCode": "PaddleDamageCoverage",
		"coverageName": "涉水损失险",
		"coverageAmount": "353080"
	],
	[
		"coverageCode": "GlassBrokenCoverage",
		"coverageName": "玻璃破碎险",
		"coverageAmount": "1"
	],
	[
		"coverageCode": "SelfIgniteCoverage",
		"coverageName": "自燃损失险",
		"coverageAmount": "353080"
	],
	[
		"coverageCode": "CarBodyPaintCoverage",
		"coverageName": "车身油漆单独损伤险",
		"coverageAmount": "2000"
	],
	[
		"coverageCode": "RiderExemptDeductibleSpecialClause",
		"coverageName": "附加险不计免赔",
		"coverageAmount": ""
	]
]
def insurancePackage = [
	thirdPartyAmount: 0,
	thirdPartyIop   : false,
	damage          : false,
	damageIop       : false,
	theft           : false,
	theftIop        : false,
	engine          : false,
	engineIop       : false,
	glass           : false,
	glassType       : 0,
	driverAmount    : 0,
	driverIop       : true,
	passengerAmount : 0,
	passengerIop    : false,
	spontaneousLoss : false,
	scratchAmount   : 0,
	scratchIop      : false,
]

println coverageInfo
def damage = 388000
def theft = 353080
def thirdParty = 100000
def scratch = 2000
def driver = 10000
def passenger = 10000
def glassType = 1

//def damage = vehicleInfo.purchasePrice
//def theft = context.theftCoverage
//def thirdParty = insurancePackage.thirdPartyAmount
//def scratch = insurancePackage.scratchAmount
//def driver = insurancePackage.passengerAmount
//def passenger = insurancePackage.driverAmount
//def glassType = insurancePackage.glassType.id

def GETLIST_BOOLEAN = { ipack, entry ->
	ipack[entry.key]  ? entry.value : null
}

def GETLIST_DOUBLE = { ipack, entry ->
	ipack[entry.key] > 0 ? entry.value : null
}

def insurancePackage_double = [
	thirdPartyAmount: ['第三者责任险', 'ThirdPartyLiabilityCoverage', "${thirdParty}"],
	driverAmount    : ['车上司机责任险', 'InCarDriverLiabilityCoverage', "${driver}"],
	passengerAmount : ['车上乘客责任险', 'InCarPassengerLiabilityCoverage', "${passenger}"],
	scratchAmount   : ['车身油漆单独损伤险', 'CarBodyPaintCoverage', "${scratch}"],
]

def insurancePackage_boolean = [
	thirdPartyIop   : ['第三者责任险不计免赔', 'ThirdPartyLiabilityExemptDeductibleSpecialClause', ""],
	damageIop       : ['车损险不计免赔', 'DamageLossExemptDeductibleSpecialClause', ""],
	theftIop        : ['全车盗抢险不计免赔', 'TheftCoverageExemptDeductibleSpecialClause', ""],
	driverIop       : ['车上人员责任险不计免赔', 'InCarPersonLiabilityExemptDeductibleSpecialClause', ""],
	passengerIop    : ['车上人员责任险不计免赔', 'InCarPersonLiabilityExemptDeductibleSpecialClause', ""],
	engineIop       : ['附加险不计免赔', 'RiderExemptDeductibleSpecialClause', ""],
	scratchIop      : ['附加险不计免赔', 'RiderExemptDeductibleSpecialClause', ""],
]

def insurancePackage_glass = [
	glass           : ['玻璃破碎险', 'GlassBrokenCoverage', "${glassType}"],
]


def insurancePackage_boolean2Double = [
	damage          : ['车辆损失险', 'DamageLossCoverage', "${damage}"],
	theft           : ['全车盗抢损失险', 'TheftCoverage', "${theft}"],
	engine          : ['涉水损失险', 'PaddleDamageCoverage', "${theft}"],
	spontaneousLoss : ['自燃损失险', 'SelfIgniteCoverage', "${theft}"],
]


def mappinglist = insurancePackage_double.collect(GETLIST_DOUBLE.curry(insurancePackage)) - null
mappinglist += insurancePackage_boolean.collect(GETLIST_BOOLEAN.curry(insurancePackage)) - null
mappinglist += insurancePackage_glass.collect(GETLIST_BOOLEAN.curry(insurancePackage)) - null
mappinglist += insurancePackage_boolean2Double.collect(GETLIST_BOOLEAN.curry(insurancePackage)) - null

//def _MAPPING_COVERAGEINFO = [
//	['车辆损失险', 'DamageLossCoverage', "${damage}"],
//	['车损险不计免赔', 'DamageLossExemptDeductibleSpecialClause', ""],
//	['第三者责任险', 'ThirdPartyLiabilityCoverage', "${thirdParty}"],
//	['第三者责任险不计免赔', 'ThirdPartyLiabilityExemptDeductibleSpecialClause', ""],
//	['全车盗抢损失险', 'TheftCoverage', "${theft}"],
//	['全车盗抢险不计免赔', 'TheftCoverageExemptDeductibleSpecialClause', ""],
//	['涉水损失险', 'PaddleDamageCoverage', "${theft}"],
//	['玻璃破碎险', 'GlassBrokenCoverage', "${glassType}"],
//	['车上司机责任险', 'InCarDriverLiabilityCoverage', "${driver}"],
//	['车上乘客责任险', 'InCarPassengerLiabilityCoverage', "${passenger}"],
//	['车上人员责任险不计免赔', 'InCarPersonLiabilityExemptDeductibleSpecialClause', ""],
//	['自燃损失险', 'SelfIgniteCoverage', "${theft}"],
//	['车身油漆单独损伤险', 'CarBodyPaintCoverage', "${scratch}"],
//	['附加险不计免赔', 'RiderExemptDeductibleSpecialClause', ""],
//]

def list = mappinglist.collect { coverageName, coverageCode,coverageAmount ->
	[
		"coverageCode": coverageCode,
		"coverageName": coverageName,
		"coverageAmount": coverageAmount
	]
}
assert list instanceof List



JsonBuilder builder = new JsonBuilder(list)
println builder.toString()